#include <stdio.h>
#include <stdlib.h>

struct Color
{
    int R, G, B;
};

int main (int argc, char const* argv[])
{
    int i;
    struct Color c, map[16];

    for (i = 0; i < 16; i++) {
        scanf("%d %d %d", &map[i].R, &map[i].G, &map[i].B);
    }

    while (scanf("%d %d %d", &c.R, &c.G, &c.B) && c.R >= 0) {
        int index = 0;
        int min = 65535;

        for (i = 0; i < 16; i++) {
            int d = (c.R - map[i].R) * (c.R - map[i].R) +
                    (c.G - map[i].G) * (c.G - map[i].G) +
                    (c.B - map[i].B) * (c.B - map[i].B);
            if (min > d) {
                min = d;
                index = i;
            }
        }

        printf("(%d,%d,%d) maps to (", c.R, c.G, c.B);
        printf("%d,%d,%d)\n", map[index].R, map[index].G, map[index].B);
    }

    return 0;
}
